package com.tgy.servlet;

import com.tgy.entity.User;
import com.tgy.utils.Sendmail;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * @ClassName: RegisterServlet
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 17:08 2021/12/13
 * @version : V1.0
 */
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String password=req.getParameter("pwd");
        String email=req.getParameter("email");

        User user=new User(username,password,email);
        //用户注册成功之后，给用户发送一封邮件
        //我们使用线程来专门发送邮件，防止出现帮时，和网站注册人数过多的情况;
        Sendmail send=new Sendmail(user);
        //启动线程，线程启动之后就会执行run方法来发送邮件
        send.start();

        //注册用户
        req.setAttribute("message","注册成功，我们已经发了一封带了注册信息的电子邮件，请查收!如网络不稳定，可能过会儿才能收到!");
        req.getRequestDispatcher( "info.jsp").forward(req,resp);

        System.out.println("success");
    }
}
